<template>
  <el-drawer
    :visible="drawer"
    :show-close="false"
    @close="handleClose"
    size="35.5%"
    class="detailDrawer"
  >
    <div class="drawerWrapper">
      <div v-if="activeKey == '1'" class="wrap">
        <el-tabs v-model="activeName" ref="tabs" @tab-click="handleClick">
          <el-tab-pane label="基本信息" name="1"></el-tab-pane>
          <el-tab-pane label="审核信息" name="2"></el-tab-pane>
        </el-tabs>

        <div v-if="activeName == '1'" class="tabContnet">
          <ul class="list">
            <li class="item">
              <div class="tit">创建时间</div>
              <div class="desc">
                {{ info.baseInfo.createTime ? info.baseInfo.createTime : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">商户订单号</div>
              <div class="desc">
                {{ info.baseInfo.merchantChargeNo ? info.baseInfo.merchantChargeNo : "-" }}
              </div>
              <div
                v-if="info.baseInfo.merchantChargeNo"
                style="margin-left: 32px; color: #03bfc6; cursor: pointer"
              >
                <i
                  class="el-icon-document-copy"
                  @click="copyAppId(info.payformNo)"
                ></i>
              </div>
            </li>
            <li class="item">
              <div class="tit">云尘付流水号</div>
              <div class="desc">
                {{ info.baseInfo.innerChargeNo ? info.baseInfo.innerChargeNo : "-" }}
              </div>
              <div
                v-if="info.baseInfo.innerChargeNo"
                style="margin-left: 32px; color: #03bfc6; cursor: pointer"
              >
                <i
                  class="el-icon-document-copy"
                  @click="copyAppId(info.innerPayformNo)"
                ></i>
              </div>
            </li>
            <li class="item">
              <div class="tit">所属商户</div>
              <div class="desc">
                {{ info.baseInfo.memberName ? info.baseInfo.memberName : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">商品名称</div>
              <div class="desc">
                {{ info.baseInfo.subject ? info.baseInfo.subject : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">订单金额/元</div>
              <div class="desc">
                {{ info.baseInfo.originalAmountStr ? info.baseInfo.originalAmountStr : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">优惠金额/元</div>
              <div class="desc">
                {{ info.baseInfo.discountAmountStr ? info.baseInfo.discountAmountStr : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">支付金额/元</div>
              <div class="desc">
                {{ info.baseInfo.payAmountStr ? info.baseInfo.payAmountStr : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">支付渠道</div>
              <div class="desc">
                {{ info.baseInfo.payChannel ? info.baseInfo.payChannel : "-" }}
              </div>
            </li>
          </ul>
        </div>
        <div v-if="activeName == '2'" class="tabContnet">
          <ul class="list">
            <li class="item">
              <div class="tit">退款发起时间</div>
              <div class="desc">
                {{ info.auditInfo.gmtCreated ? info.auditInfo.gmtCreated : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款发起人</div>
              <div class="desc">
                {{ info.auditInfo.refundPromoter ? info.auditInfo.refundPromoter : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款金额/元</div>
              <div class="desc">
                {{ info.auditInfo.refundAmountStr ? info.auditInfo.refundAmountStr : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款理由</div>
              <div class="desc">
                {{ info.auditInfo.refundReason ? info.auditInfo.refundReason : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核人</div>
              <div class="desc">
                {{ info.auditInfo.auditUser ? info.auditInfo.auditUser : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核状态</div>
              <div class="desc">
                {{ info.auditInfo.auditStatus ? info.auditInfo.auditStatus : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核时间</div>
              <div class="desc">
                {{ info.auditInfo.auditTime ? info.auditInfo.auditTime : "-" }}
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div v-if="activeKey == '2'" class="wrap">
        <el-tabs v-model="activeName" ref="tabs" @tab-click="handleClick">
          <el-tab-pane label="基本信息" name="1"></el-tab-pane>
          <el-tab-pane label="审核信息" name="2"></el-tab-pane>
        </el-tabs>
        <div v-if="activeName == '1'" class="tabContnet">
          <ul class="list">
            <li class="item">
              <div class="tit">退款批次号</div>
              <div class="desc">
                {{ info.baseInfo.batchNo ? info.baseInfo.batchNo : "-" }}
              </div>
            </li>
            <li class="item-table">
              <el-table :data="info.baseInfo.refundList">
                <template slot="empty">
                  <el-empty
                    :image="require('@/assets/imgs/middleWork/k1.png')"
                    :image-size="80"
                    description="暂无相关数据"
                  ></el-empty>
                </template>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="商户订单号"
                  prop="merchantChargeNo"
                  :width="
                    this.$flexColumnWidth(
                      'merchantChargeNo',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{ scope.row.merchantChargeNo ? scope.row.merchantChargeNo : "-" }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="云尘付流水号"
                  prop="innerChargeNo"
                  :width="
                    this.$flexColumnWidth(
                      'innerChargeNo',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.innerChargeNo
                          ? scope.row.innerChargeNo
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="所属商户"
                  prop="memberName"
                  :width="
                    this.$flexColumnWidth(
                      'memberName',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{ scope.row.memberName ? scope.row.memberName : "-" }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="商品名称"
                  prop="subject"
                  :width="
                    this.$flexColumnWidth(
                      'subject',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{ scope.row.subject ? scope.row.subject : "-" }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="订单金额"
                  prop="originalAmountStr"
                  :width="
                    this.$flexColumnWidth(
                      'originalAmountStr',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.originalAmountStr
                          ? scope.row.originalAmountStr
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="优惠金额"
                  prop="discountAmountStr"
                  :width="
                    this.$flexColumnWidth(
                      'discountAmountStr',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.discountAmountStr
                          ? scope.row.discountAmountStr
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="支付金额"
                  prop="fmtActualAmount"
                  :width="
                    this.$flexColumnWidth(
                      'payAmountStr',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.payAmountStr
                          ? scope.row.payAmountStr
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="退款金额"
                  prop="refundAmountStr"
                  :width="
                    this.$flexColumnWidth(
                      'refundAmountStr',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.refundAmountStr
                          ? scope.row.refundAmountStr
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="支付渠道"
                  prop="payChannel"
                  :width="
                    this.$flexColumnWidth(
                      'payChannel',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{ scope.row.payChannel ? scope.row.payChannel : "-" }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  label="退款状态"
                  prop="refundStatus"
                  :width="
                    this.$flexColumnWidth(
                      'refundStatus',
                      info.baseInfo.refundList
                    )
                  "
                >
                  <template slot-scope="scope">
                    <div
                      style="
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                    >
                      {{
                        scope.row.refundStatus
                          ? scope.row.refundStatus
                          : "-"
                      }}
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </li>
          </ul>
        </div>
        <div v-if="activeName == '2'" class="tabContnet">
          <ul class="list">
            <li class="item">
              <div class="tit">退款发起时间</div>
              <div class="desc">
                {{ info.auditInfo.gmtCreated ? info.auditInfo.gmtCreated : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款发起人</div>
              <div class="desc">
                {{ info.auditInfo.refundPromoter ? info.auditInfo.refundPromoter : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款总金额/元</div>
              <div class="desc">
                {{ (info.auditInfo.refundAmountStr) }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款总笔数/笔</div>
              <div class="desc">
                {{
                  info.auditInfo.refundCount
                    ? info.auditInfo.refundCount
                    : "-"
                }}
              </div>
            </li>
            <li class="item">
              <div class="tit">退款理由</div>
              <div class="desc">
                {{ info.auditInfo.refundReason ? info.auditInfo.refundReason : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核人</div>
              <div class="desc">
                {{ info.auditInfo.auditUser ? info.auditInfo.auditUser : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核状态</div>
              <div class="desc">
                {{ info.auditInfo.auditStatus ? info.auditInfo.auditStatus : "-" }}
              </div>
            </li>
            <li class="item">
              <div class="tit">审核时间</div>
              <div class="desc">
                {{ info.auditInfo.auditTime ? info.auditInfo.auditTime : "-" }}
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  props: {
    drawer: {
      type: Boolean,
    },
    info: {
      type: Object,
      default: () => ({}),
    },
    activeKey: {
      type: String,
      default: "1",
    },
    width: {
      type: String,
      default: "140px",
    },
  },
  components: {},
  data() {
    return {
      resetKey: false,
      activeName: "1",
    };
  },
  methods: {
    handleClose() {
      this.$emit("update:drawer", false);
      this.activeName = "1";
    },
    handleClick() {
      this.resetActivePosition(this.$refs.tabs.$el);
    },
    resetActivePosition($el) {
      this.$nextTick(() => {
        const activeEl = $el.querySelector(".el-tabs__item.is-active");
        const lineEl = $el.querySelector(".el-tabs__active-bar");
        const style = getComputedStyle(activeEl);
        const pl = style.paddingLeft.match(/\d+/)[0] * 1;
        const pr = style.paddingRight.match(/\d+/)[0] * 1;
        const w = style.width.match(/\d+/)[0] * 1;
        lineEl.style.transform =
          "translateX(" + (activeEl.offsetLeft + pl) + "px)";
        lineEl.style.width = w - pl - pr + "px";
      });
    },
    copyAppId(value) {
      const input = document.createElement("input"); // 创建input对象
      input.value = value; // 设置复制内容
      document.body.appendChild(input); // 添加临时实例
      input.select(); // 选择实例内容
      document.execCommand("Copy"); // 执行复制
      document.body.removeChild(input); // 删除临时实例
      this.$message.success("复制成功！");
    },
  },
};
</script>

<style lang="scss" scoped>
.drawerWrapper {
  padding: 0 50px;
}

.tabContnet {
  margin-top: 30px;
  .item {
    display: flex;
    align-items: flex-start;
    min-height: 20px;
    // line-height: 40px;
    margin-bottom: 20px;
    div {
      // display: inline-block;
      &.tit {
        min-width: 88px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #869daa;
        margin-right: 26px;
      }
      &.desc {
        display: flex;
        // justify-content: space-around;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #1d1c1c;
        span {
          display: inline-block;
          margin-right: 10px;
          &.hidText {
            display: inline-block;
            width: 230px;
            overflow: hidden; //溢出隐藏
            white-space: nowrap; //禁止换行
            text-overflow: ellipsis; //...
          }
          &.highCol {
            color: #03bfc6;
          }
        }
      }
    }
  }
  .item-table {
    margin-top: 17px;
    :deep(.el-table .el-table__header-wrapper .el-table__cell) {
      height: 34px;
    }
    :deep(.el-table .el-table__body-wrapper .el-table__cell) {
      height: 34px;
    }
  }
}

:deep(.el-tabs__item) {
  width: 72px !important;
  font-size: 18px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  margin-right: 40px;
}
:deep(.el-tabs__active-bar) {
  top: unset;
  bottom: 0;
  height: 1px;
}
</style>
